package com.wbp.cms.core.project.service;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.google.common.base.Preconditions;
import com.wbp.cms.client.project.domain.ContractDO;
import com.wbp.cms.client.project.service.ContractService;
import com.wbp.cms.client.result.BaseResultCode;
import com.wbp.cms.client.result.Result;
import com.wbp.cms.core.project.dao.ContractDAO;


/**
 * @Description:
 * @Department:
 * @author andy.lhc
 * @date 2016年3月9日 下午3:10:18
 */
@Service("contractService")
public class ContractServiceImpl implements ContractService {
  /**
   * 
   */
  private static final long serialVersionUID = 2297851565716747346L;

  @Resource
  private ContractDAO  contractDAO ;

  @Override
  public Result<Long> addContract(ContractDO contractDO) {
    Preconditions.checkNotNull(contractDO, "contractDO不能为null") ;
    
    return Result.buildSuccess( contractDAO.insert(contractDO) ) ;
  }
 
  @Override
  public Result<Boolean> modifyContract(ContractDO contractDO) {
    Preconditions.checkNotNull(contractDO, "contractDO不能为null") ; 
    
    return Result.buildSuccess(contractDAO.update(contractDO) > 0 );
  }
   
  @Override
  public Result<ContractDO> loadContract(Long contractId) {
    Preconditions.checkNotNull(contractId, "contractId:"+contractId+",不能为null") ;
    Preconditions.checkArgument( contractId > 0, "contractId:"+contractId+",应>0");
    
    ContractDO contract = contractDAO.load(contractId) ;
    if(contract == null)
      return Result.buildError(BaseResultCode.CONTRACT_QUERY_NOT_FUND) ;
    return Result.buildSuccess(contract);
  }
  
  @Override
  public ContractDO loadContractByProject(Long projectId) {
    Preconditions.checkNotNull(projectId, "projectId:"+projectId+",不能为null") ;
    Preconditions.checkArgument( projectId > 0, "projectId:"+projectId+",应>0");
    
    return contractDAO.loadByProjectId(projectId) ;
  }

  
}
